﻿using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using BLL;
using IFactory;

public partial class Quarter_QuarterResolveDetailShow : System.Web.UI.Page
{
    QuarterDateManager dllQuarterDateManager = new QuarterDateManager();
    QuarterPlanofManager dllQuarterPlanofManager = new QuarterPlanofManager();
    IBussinessLogic dllQuarterPlanDetail = new QuarterPlanDetailManager();
    Authentication dllAuthentication = new Authentication();
    protected void Page_Load(object sender, EventArgs e)
    {
        dllAuthentication.isLogin();
        //得到年度计划信息  
        if (!IsPostBack)
        {
            int _quarterId = Utility.HttpHelp.getParamsInt("Id");
            if (_quarterId == 0)
            {
                Response.Redirect("QuarterResolveList.aspx");
            }
            else
            {
                //根据id得到年度计划的信息
                object[] _value = new object[1];
                _value[0] = _quarterId;
                DataTable _quarter = dllQuarterDateManager.get(QuarterDateManager.field.Quarter_Id.ToString(), _value);
                if (_quarter.Rows.Count != 0)
                {
                    lbltitle.Text = _quarter.Rows[0]["QuarterYear"].ToString() + "年" + _quarter.Rows[0]["QuarterName"].ToString();
                }
                //绑定
                bindGridViewQuarterPlan();
            }
        }
    }


    /// <summary>
    /// 绑定年计划GridView
    /// </summary>
    /// <author>grokyao</author>
    /// <date>2009-2-5</date>
    void bindGridViewQuarterPlan()
    {
        int _quarterId = Utility.HttpHelp.getParamsInt("Id");
        object[] _value = new object[1];
        _value[0] = _quarterId;
        DataTable _quarterPlan = dllQuarterPlanofManager.get(QuarterPlanofManager.field.QuarterDate.ToString(), _value);
        gvlist.DataSource = _quarterPlan;
        gvlist.DataBind();
    }


    /// <summary>
    /// 绑定年分解计划GridView
    /// </summary>
    /// <author>grokyao</author>
    /// <date>2009-2-5</date>
    void bindGridViewQuarterResolve(string _quarterPlanId)
    {
        object[] _value = new object[1];
        _value[0] = _quarterPlanId;
        DataTable _quarterResolve = dllQuarterPlanDetail.get(QuarterPlanDetailManager.field.QuarterPlanId.ToString(), _value);
        this.gdvQuarterResolve.DataSource = _quarterResolve;
        this.gdvQuarterResolve.DataBind();
    }




    /// <summary>
    /// GridView自动分页
    /// </summary>
    /// <param name="sender"></param>
    /// <param name="e"></param>
    protected void gvlist_PageIndexChanging(object sender, GridViewPageEventArgs e)
    {
        gvlist.PageIndex = e.NewPageIndex;
        bindGridViewQuarterPlan();
        //分页的时候把下面的gridview隐藏
        this.gdvQuarterResolve.Visible = false;
    }

    /// <summary>
    /// 查看年分解计划事件
    /// </summary>
    /// <param name="sender"></param>
    /// <param name="e"></param>
    protected void btnResolve_Click(object sender, EventArgs e)
    {
        
        int i = 0;
        Button bt = (Button)sender;//获得当前控件
        TableCell cell = (TableCell)bt.Parent;//得到所处的父单元格
        GridViewRow iRow = (GridViewRow)cell.Parent;//得到所处父单元行
        i = iRow.RowIndex;//得到该行的索引
        bindGridViewQuarterResolve(this.gvlist.Rows[i].Cells[0].Text);
        //点击查看年分解计划按钮的时候，下面的gridview显示
        this.gdvQuarterResolve.Visible = true;
    }
}
